package com.sun.controller;

import com.sun.pojo.File;
import com.sun.service.FtpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;

/**
 * @author lk
 */
@RestController
public class FtpUploadController {

    @Autowired
    private FtpService ftpService;

    @PostMapping("/upload")
    public String upload(@RequestParam("file")MultipartFile updateFile) throws IOException {

        String originalFilename = updateFile.getOriginalFilename();
        String upload = ftpService.upload(originalFilename);
        return upload;
    }

    @GetMapping("/down")
    public String down(@RequestParam("name")String name){

        return ftpService.downloadByName(name);
    }

    @GetMapping("/all")
    public List<File> findAll(){
        return ftpService.findAll();
    }
}
